<template>
    <div class="management1">
        <header>
            <div>
                <fourLevelLinkage
                    @changeProvince="changeProvince"
                    @changeCity="changeCity"
                    @changeArea="changeArea"
                    @changeHospital="changeHospital"
                    :province="province"
                    :city="city"
                    :area="area"
                    :hospital="hospital"
                ></fourLevelLinkage>
            </div>
            <Input
                v-model.trim="val"
                placeholder="请输入医疗机构名称检索"
                class="jigou"
                clearable
            />
            <Button type="primary" icon="ios-search" @click="search"  style="width:51px;height:35px;"></Button>
        </header>
        <Table stripe :columns="columns1" :data="tableList"></Table>
        <div class="page">
            <Page :total="homeSize" :current='pageNo' show-total show-elevator @on-change="pageChange"/>
        </div>
    </div>
</template>

<script>
import api from "@/api/commonApi";
import fourLevelLinkage from "@/components/fourLevelLinkage";
import aesUtils from "@/plugins/aes-utils.js";
import store from "@/store";
export default {
    components: {
        fourLevelLinkage
    },
    data() {
        return {
            province: null,
            city: null,
            area: null,
            hospital: null,
            tableList: [],
            val: "",
            homeSize: 10,
            pageSize: 10,
            pageNo:1,
            columns1:[
                {
                    title: '排序',
                    key: 'sum',
                    align: 'center',
                    width: 60,
                    render: (h, params) => {
                        let sum = (this.pageNo-1)*this.pageSize + params.index +1;
                        return h("span", sum);
                    }
                },
                {
                    title: '区域',
                    key: 'provinceName',
                    align: 'center',
                    // width: 80,
                },
                {
                    title: '机构名称',
                    key: 'orgName',
                    align: 'center',
                    // width: 150,
                },
                {
                    title: '收费项目数',
                    key: 'dxCount',
                    align: 'center',
                    // width: 150,
                },
                {
                    title: '组合项目数',
                    key: 'zhCount',
                    align: 'center',
                    // width: 120,
                },
                {
                    title:"套餐项目数",
                    key:"tcCount",
                    align: 'center',
                    // width: 120,
                },
                {
                    title:"设置",
                    align: 'center',
                    width: 120,
                    fixed:'right',
                    render: (h,params) => {
                        let a = params.row
                        return h('div', [
                            h('span', {
                                style: {
                                    color: " #5362e1",
                                },
                                on: {
                                    click: () => {
                                        this.navto(a)
                                    }
                                }
                            }, '编辑')
                        ])
                    }
                }
            ]
        };
    },
    created() {
        let breadList = [
            { path: "/index", title: "首页" },
            {
                path: "/index/operation/feeStandard/list",
                title: "机构运营"
            },
            {
                path: "/index/operation/home",
                title: "机构运营配置管理"
            }
        ];
        this.$emit("changeBreadList", breadList);
    },
    mounted() {
        this.getDate(1);
    },
    methods: {
        changeProvince(val) {
            this.province = val;
        },
        changeCity(val) {
            this.city = val;
        },
        changeArea(val) {
            this.area = val;
        },
        changeHospital(val) {
            this.hospital = val;
        },
        // 获取医院列表
        getDate(pageNo, val) {
            this.pageNo = pageNo;
            let params = {
                pageNo,
                pageSize: 10
            };
            if (Boolean(val)) {
                params.orgName = val.trim();
            }
            params.provinceCode = this.province ? this.province : null;
            params.cityCode = this.city ? this.city : null;
            params.districtCode = this.area ? this.area : null;
            params.hospitalId = this.hospital ? this.hospital : null;
            // console.log("机构配置管理列表 params",params);
            this.$axios
                .post(api.findHospitalPage, params)
                .then(res => {
                    if (res.data.code==1) {
                        let ret = res.data.object.records;
                        this.homeSize = res.data.object.total;
                        if(ret){
                            ret.forEach((item,index) =>{
                            item.sum = this.addZeros(index)
                                item.hospitalType = item.hospitalType == 1 ? '医院' :""
                            })
                            this.tableList = ret;
                        } else {
                            this.tableList = []
                        }
                    } else {
                        this.$Message.error("没有访问权限");
                    }
                })
                .catch(err => {
                    console.log(err);
                });
        },
        pageChange(index) {
            this.getDate(index, this.val);
        },
        navto(item) {
            let iv = store.state.iv;
            let salt = store.state.salt;
            sessionStorage.setItem("hospitalId", item.hospitalId);
            sessionStorage.setItem("orgCode", item.orgCode);
            localStorage.setItem(
                "hospitalName",
                aesUtils.encrypt(salt, iv, "Doctortoservice", item.orgName)
            );
            this.$router.push({
                name: "homeInfo"
            });
            if(item.hospitalId){
                this.functionJS.queryNavgationTo(this, "/index/directory/priceManagement/index", {
                    hospitalId:item.hospitalId,
                });
            } else {
                this.functionJS.queryNavgationTo(this, "/index/directory/priceManagement/index")
            }
        },
        search() {
            this.getDate(1, this.val);
        }
    }
};
</script>

<style scoped lang = "less">
.management1 {
    width: 100%;
    padding:10px;
    margin: 0 auto;
    background: #fff;
    header {
        width: 100%;
        display: flex;
        flex-direction: row;
        margin: 10px 0;
        span {
            color: black;
            line-height: 30px;
            margin-right: 10px;
        }
    }
    .jigou{
        margin: 0 10px;
        width: 200px;
    }
    .page{
      text-align: center;
      margin: 20px 0;
    }
}
</style>
 